<?php

print_r("top");

	/**
	 * Friend request plugin
	 * List all the requests (sent and received)
	 * 
	 * @package friend_request
	 * @author ColdTrick IT Solutions
	 * @copyright Coldtrick IT Solutions 2009
	 * @link http://www.coldtrick.com/
	 * @version 2.1
	 */

	gatekeeper();
	
	$user = get_loggedin_user();
	
	// set the correct context and page owner
	set_context("friends");
	set_page_owner($user->guid);
	
	// fix to show collections links
	collections_submenu_items();
	
	// Get all the data
//	$received_count = elgg_get_entities_from_relationship("follower", $user->guid, true, "user", "", 0, "", 0, 0, true);
//	$received_requests = elgg_get_entities_from_relationship("follower", $user->guid, true, "user", "", 0, "", $received_count);
	
	$followers = elgg_get_entities_from_relationship(array(
		'type' => 'user',
		'relationship' => 'new_follower',
		'relationship_guid' => elgg_get_page_owner_guid(),
		'inverse_relationship' => true,
		'order_by' => 'r.time_created Desc',
	));
	
	print_r(" middle ");
	
	$count = sizeof($followers);
	
	// Get page elements
	$title = elgg_view_title(elgg_echo('followers:title'));
	
	$received = elgg_view("followers/latest_followers", array("entities" => $followers, "request_count" => $count));
	//$sent = elgg_view("friend_request/sent", array("entities" => $sent_requests, "request_count" => $sent_count));
	
	
	//replace new_follower relationship with follower - MK
	foreach($followers as $follower){
		print_r("page owner: ".elgg_get_page_owner_guid());
		print_r(" follower: ".$follower->guid);
		
		if (remove_entity_relationship($follower->guid, "new_follower", elgg_get_page_owner_guid())){
			print_r("success");
		}	
		else{
			print_r("problem");
		}
	}
	
	
	// Build page
	$page_body =  $title . $received . $sent;
	
	// Draw page
	page_draw(elgg_echo("followers:title"), elgg_view_layout('two_column_left_sidebar', '', $page_body));
	


?>